package rebellion.util;

import ratkit.repast.RepastScenarioBuilder;
import rebellion.Constants;
import repast.simphony.context.space.continuous.ContinuousSpaceFactoryFinder;
import repast.simphony.context.space.grid.GridFactoryFinder;
import repast.simphony.space.continuous.ContinuousSpace;
import repast.simphony.space.continuous.RandomCartesianAdder;
import repast.simphony.space.grid.Grid;
import repast.simphony.space.grid.GridBuilderParameters;
import repast.simphony.space.grid.RandomGridAdder;

/**
 * Abstract scenario builder for Rebellion test scenario test cases.
 * 
 * @author İbrahim Çakırlar
 * 
 */
abstract public class RebellionScenarioBuilder extends RepastScenarioBuilder {

	/**
	 * Grid of the test environment.
	 */
	private Grid<Object> grid;

	@SuppressWarnings({ "unused", "unchecked" })
	@Override
	protected void createGridAndContinuousSpace() {
		getContext().setId(Constants.CONTEXT_ID);

		int gridWidth = 50;
		int gridHeight = 50;
		// create space
		final ContinuousSpace<Object> space = ContinuousSpaceFactoryFinder
				.createContinuousSpaceFactory(null)
				.createContinuousSpace(
						Constants.SPACE_ID,
						getContext(),
						new RandomCartesianAdder<Object>(),
						new repast.simphony.space.continuous.WrapAroundBorders(),
						gridWidth, gridHeight);

		// create grid
		setGrid(GridFactoryFinder.createGridFactory(null).createGrid(
				Constants.GRID_ID,
				getContext(),
				new GridBuilderParameters<Object>(
						new repast.simphony.space.grid.WrapAroundBorders(),
						new RandomGridAdder<Object>(), false, gridWidth,
						gridHeight)));

	}

	/**
	 * Sets the grid.
	 */
	public void setGrid(Grid<Object> grid) {
		this.grid = grid;
	}

	/**
	 * @return the test grid instance for test agents.
	 */
	public Grid<Object> getGrid() {
		return grid;
	}
}
